constructor:

Def: "Its a piece OR block of code which can be reused"

It is a instance member of the class. To access instance members we have to create a object to the class.


Q: What is Constructor?
Ans: It is block of code which can be reused.


Q: Why constructors are required?
Ans: 
(a) It is used to create a object to the class.
(b) It is used to assign the values to the instance variable
(c) It is used to call & run the instance members


Note: Rules for Constructor:

1. Every class by default will have one constructor which is k.a., default constructor.

2. The default constructor will be created by the compiler in java.

3. We can create more than one constructor inside the class having different set of signatures/Parameters (Constructor overloading)

4. The constructor can be written with arguments (Parameterized constructor) or without arguments(default constructor). Hence there are 2 types of constructors:
  (a) Default Constructor
  (b) Parameterized Constructor

5. Constructor cannot return any value.

6. The constructor name is pre-defined (must be same as class name).

7. Multiple constructor in the class requires creation of multiple objects in order to access/execute all of them.

8. If we create a parameterized constructor in the class then the default constructor will not be available. To get it back we need to explicitly create a default constructor.
---------------------------------------------

Constructor Overloading (CO):
    Writing more than one constructors inside the class where constructor name is same but having different signatures (arguments) is k.a., Constructor Overloading.

Rules for CO:
1. The no. of arguments used in the constructors should be different

2. The datatype of the arguments used in the constructors should be different.

3. The Sequence of datatype of the arguments used in the constructors should be different
------------------------------------------------

Drawback of constructors:

1. Constructor names are predefined
2. Constructor will not return any value
3. Multiple Constructor requires creation of multiple objects in order to execute all the constructor
4. If we want to perform different tasks using constructor which requires same set of parameters is not possible in constructor
5. Constructor overriding is not supported as the constructor name should be similar to the class name.
6. Constructor names are ambiguous/Confusing in nature.


--------------------------------------------------------------------
Q: Can constructor return values?
Q: Can we create multiple construcor in the same class?
Q: What happens when we create a object to the class?
Ans: The corresponding constructor will get execute.

Q: Write a constructor for matrix multiplication?
Q: Write a construcor for displaying the missing numbers from the array?
Q: Write a construcor for substration of 2 array values?
Q: Write a construcor to print pyramid pattern using numbers
       1
	 2   3
  4    5    6
Q: Write a construcor to find the city names "Bangalore" is present in the array?
Q: Write a construcor to find that how many times the "Bangalore" name is repeated in the array?
Q: Write a construcor to display the non-duplicate/unique values from the array?
Q: Write a construcor to find addition of elements which is equal to the given number?